#-*- codeing = utf-8 -*-
#@Time : 2020/8/30 21:04
#@Author : 阳某
#@File : testcsv.py
#@Software : PyCharm
import csv

headers = ['class','name','sex','height','year']

rows = [
        [1,'xiaoming','male',168,23],
        [1,'xiaohong','female',162,22],
        [2,'xiaozhang','female',163,21],
        [2,'xiaoli','male',158,21]
    ]

with open('test.csv','w',encoding='utf-8-sig',newline='')as f:
    f_csv = csv.writer(f,delimiter =',')   #delimiter = ' '
    f_csv.writerow(headers)
    f_csv.writerows(rows)